package com.cn.serverline.lineicp.produce.controller;

import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import com.cn.serverline.lineicp.produce.entity.dto.ContinueDto;
import com.cn.serverline.lineicp.produce.entity.vo.AssemblyTaskVo;
import com.cn.serverline.lineicp.produce.entity.vo.AssemblysTaskVo;
import com.cn.serverline.lineicp.produce.entity.dto.AddStartTimeDto;
import com.cn.serverline.lineicp.produce.entity.dto.EquipmentTaskDto;
import com.cn.serverline.lineicp.produce.entity.vo.EquipmentTaskVo;
import com.cn.serverline.lineicp.produce.entity.vo.MaterialComponentsVo;
import com.cn.serverline.lineicp.produce.entity.vo.MaterialResourcesVo;
import com.cn.serverline.lineicp.produce.service.TaskService;
import com.cn.serverline.lineicp.workshopPlan.entity.request.ExamineRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/task")
@Api(tags = "任务管理")
@ApiResource(name = "任务管理")
public class TaskController {

    @Autowired
    private TaskService taskService;

    /**
     * 获取部装任务
     * @param equipmentTaskDto
     * @return
     */
    @GetMapping("/getEquipment")
    @ApiOperation(value = "获取部装任务")
    public ResponseData<List<EquipmentTaskVo>> getEquipment(EquipmentTaskDto equipmentTaskDto) {
        return new SuccessResponseData<>(taskService.getEquipment(equipmentTaskDto));
    }

    /**
     * 获取总装任务
     * @param equipmentTaskDto
     * @return
     */
    @GetMapping("/getAssembly")
    @ApiOperation(value = "获取总装任务")
    public ResponseData<List<AssemblysTaskVo>> getAssembly(EquipmentTaskDto equipmentTaskDto) {
        return new SuccessResponseData<>(taskService.getAssembly(equipmentTaskDto));
    }

    /**
     * 获取总装进行中的任务
     * @param equipmentTaskDto
     * @return
     */
    @GetMapping("/getAssemblyIn")
    @ApiOperation(value = "获取总装任务详情")
    public ResponseData<List<AssemblyTaskVo>> getAssemblyIn(EquipmentTaskDto equipmentTaskDto) {
        return new SuccessResponseData<>(taskService.getAssemblyIn(equipmentTaskDto));
    }


    @PostMapping("/CommencementInspectionExamine")
    @ApiOperation(value = "开工检查(消耗材料、零组件)")
    public ResponseData<List<MaterialComponentsVo>> CommencementInspectionExamine(@RequestBody @Validated ExamineRequest examineRequest) {
        List<MaterialComponentsVo> commencementInspectionExamine = taskService.CommencementInspectionExamine(examineRequest);
        return new SuccessResponseData<>(commencementInspectionExamine);
    }

    @PostMapping("/CommencementResourcesExamine")
    @ApiOperation(value = "开工检查(工装、工具、设备)")
    public ResponseData<List<MaterialResourcesVo>> CommencementResourcesExamine(@RequestBody @Validated ExamineRequest examineRequest) {
        List<MaterialResourcesVo> commencementInspectionExamine = taskService.CommencementResourcesExamine(examineRequest);
        return new SuccessResponseData<>(commencementInspectionExamine);
    }

    @PostMapping("/AddStartTime")
    @ApiOperation(value = "保存开工时间")
    public ResponseData<String> AddStartTime(@RequestBody @Validated AddStartTimeDto addStartTimeDto) {
        taskService.AddStartTime(addStartTimeDto);
        return new SuccessResponseData<>("保存成功");
    }
    @PutMapping("/AddEndTime/{id}")
    @ApiOperation(value = "保存完工时间")
    public ResponseData<String> AddEndTime(@PathVariable("id") Long id) {
        taskService.AddEndTime(id);
        return new SuccessResponseData<>("保存成功");
    }


    /**
     * 修改部装继续状态
     * @param continueDto
     * @return
     */
    @PostMapping("/continue")
    @ApiOperation(value = "修改部装继续状态")
    public ResponseData continueTask(@RequestBody @Validated ContinueDto continueDto) {
        taskService.continueTask(continueDto);
        return new SuccessResponseData<>("修改成功");
    }
    /**
     * 修改总装继续状态
     * @param continueDto
     * @return
     */
    @PostMapping("/continues")
    @ApiOperation(value = "修改总装继续状态")
    public ResponseData continueTasks(@RequestBody @Validated ContinueDto continueDto) {
        taskService.continueTasks(continueDto);
        return new SuccessResponseData<>("修改成功");
    }
}
